﻿//销售退货单管理 首页
var columns =
            [
                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '销售退货单单号', name: 'ReturnBillNo', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '仓库名称', name: 'StorehouseName', mintWidth: 80, width: 140 },
                { display: '销售退货客户', name: 'ClientName', mintWidth: 80, width: 120 },
                {display: '销售退货金额(元）', name: 'ReturnMoney', mintWidth: 80, width: 120, type: 'int' },
                { display: '退货时间', name: 'ReturnTime', mintWidth: 180, width: 180, type: 'selfDate' },
                 { display: 'BillState', name: 'BillState', hide: 1 },
                   { display: 'AuditState', name: 'AuditState', type: 'text', hide: 1 },
                  { display: '订单状态', name: 'BillStateName', mintWidth: 80, width: 80 },
                { display: '审核人', name: 'AuditorName', mintWidth: 80, width: 120 },
                { display: '审核时间', name: 'AuditTime', mintWidth: 180, width: 180, type: 'selfDate' },
                { display: '审核状态', name: 'AffirmStateName', mintWidth: 100, width: 140 },
               // { display: '是否结算', name: 'SettleState', mintWidth: 100, width: 140 },
                { display: '备注', name: 'Remarks', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
    initDataControls();
});

function initligerGrid() {
    manager = null;
    manager = $("#ProductReturnGrid").ligerGrid({
        columns: columns,
        title: '销售退货单管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                    { line: true },
//                                     { text: '提交', click: confirmOperation, icon: 'modify' },
//                                    { line: true },
//                                     { text: '审核', click: audioOperation, icon: 'modify' },
//                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
                                     { line: true },
                                    { text: '打印', click: printOperation, img: '../Content/images/print.png' },
                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), billNo: $("#billNo").val(), returnClient: $("#returnClient").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val() },
        url: "../ProductReturn/GetJsonOfDatas?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Id); }
    });
}


//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    dialogView(billId);
  }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../ProductReturn/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: "../ProductReturn/Add?orgCode=" + $("#HidOrgCode").val(), height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    if (row["BillState"].toString() == "1") { $.ligerDialog.success('已提交，不能修删除!'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../ProductReturn/Delete?billId=" + row["Id"].toString() + "&ids=all&rand=" + Math.random(), {}, function (data) {
                if (data != undefined && data == "9") {
                    initligerGrid();
                }
            });
        }
    });
}
//function deleteOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
//    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
//        if (yes) {
//            if (row["BillState"] == 1) { $.ligerDialog.success('已提交，不能删除！'); return; }
//            $.get("../ProductReturn/Delete?billId=" + row["Id"].toString() + "&ids=all&rand=" + Math.random(), {}, function (data) {
//                if (data != undefined && data == "9") {
//                    initligerGrid();
//                }
//            });
//        }
//    });
//}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    if (row["BillState"].toString() == "1") { $.ligerDialog.success('已提交，不能修改!'); return; }
        $.ligerDialog.open({ url: "../ProductReturn/Add?orgCode=" + $("#HidOrgCode").val()+"&id=" + row.Id, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}

//审核 
function audioOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要审核的行!'); return;
    }
    $.ligerDialog.open({ url: "../ProductReturn/Add?orgCode=" + $("#HidOrgCode").val() + "&id=" + row.Id, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}


////审核 
//function audioOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) {
//        $.ligerDialog.success('请选择要编辑的行!'); return;
//    }
//    $.ligerDialog.confirm('确定要审核吗？', function (yes) {
//        if (yes) {
//            $.get("../ProductReturn/Audit?billId=" + row.Id + "&rand=" + Math.random(), {}, function (data) {
//                if (data != undefined && data == "9") {
//                    $.ligerDialog.success('审核成功!');
//                    initligerGrid();
//                }
//            });
//        }
//    });
//}
//提交 
function confirmOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要提交的行!'); return; }
    $.ligerDialog.confirm('确定要提交吗？', function (yes) {
        if (yes) {
            $.get("../ProductReturn/ConfirmBill?billId=" + row.Id + "&rand=" + Math.random(), {}, function (data) {
                if (data != undefined && data == "9") {
                    $.ligerDialog.success('审核成功!');
                    initligerGrid();
                }
            });
        }
    });
}

//print
function printOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要打印的行!'); return;
    }
    if (row["AuditState"].toString() != "1") { $.ligerDialog.success('单据未审核或审核未通过，不能打印!'); return; }
    window.showModalDialog("../ProductReturn/Print?billId=" + row["Id"].toString(), window, "scroll:yes;dialogWidth=800;dialogHeight=600");
   // window.location.href = "../ProductReturn/Print?billId=" + row["Id"].toString();
}



//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}